﻿using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;

namespace MCPClientConsole
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            // 创建一个基于标准输入输出的客户端传输对象  
            var clientTransport = new StdioClientTransport(new StdioClientTransportOptions
            {
                Name = "Current MCP Server", // 传输的名称  
                Command = @"C:\Program Files\PEER Group\PTO 8.6 SP2\软件\MCPSample\MCPServerConsole\bin\Debug\net8.0\MCPServerConsole.exe" // 要执行的命令路径（对应MCPServerDemo） 的绝对路径 
            });

            // 创建一个基于SSE输入输出的客户端传输对象
            //var clientTransport = new HttpClientTransport(new HttpClientTransportOptions
            //{
            //    Endpoint = new Uri("http://localhost:5000/sse"),
            //    Name = "Local MCP Server",
            //    TransportMode = HttpTransportMode.Sse,
            //});

            await using var mcpClient = await McpClient.CreateAsync(clientTransport);

            var tools = await mcpClient.ListToolsAsync();// 列出可用的Tools
            foreach (var tool in tools)
            {
                Console.WriteLine($"{tool.Name} ({tool.Description})");
            }

            Console.WriteLine($"调用echo");
            // 直接执行Tool
            CallToolResult result = await mcpClient.CallToolAsync("echo", new Dictionary<string, object?> { ["message"] = "Shanghai" });
            Console.WriteLine($"Output：{result.Content.Select(s => (TextContentBlock)s).First(c => c.Type == "text").Text}");
        }
    }
}
